﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SGRapidForm.Common;
using SGRapidForm.Foundation.Service.Interface;
using DevExpress.Web.ASPxMenu;
using System.Xml;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxTreeList;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Permission.Entity;

namespace SGRapidForm.Foundation
{
    public partial class AreaMaintance : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");
        private IFoundationService _foundationService = ServiceProxyFactory.Create<IFoundationService>("foundationservice");
        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
           
            tlAreaList.DataSource = _foundationService.GetAreaAll();
            tlAreaList.DataBind();
            tlAreaList.ExpandToLevel(2);
        }

        /// <summary>
        /// 添加快捷方式
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public bool SaveFastAdd()
        {
            string userkeyid = ApplicationContext.Current.UserKeyid;
            string pagecode = this.GetType().Name;
            PageEntity page = _permissionService.Page_GetKeyidBypagename(pagecode);
            if (page != null)
            {
                return _permissionService.Shortcuts_Add(userkeyid, page.Keyid);
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 菜单项绑定事件 - 实现操作权限控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void menuHeader_ItemDataBound(object sender, MenuItemEventArgs e)
        {
            IHierarchyData itemHierarchyData = (IHierarchyData)e.Item.DataItem;
            XmlElement element = (XmlElement)itemHierarchyData.Item;
        }

        /// <summary>
        /// 自定义TreeList回调重新绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void tlAreaList_CustomCallback(object sender, TreeListCustomCallbackEventArgs e)
        {

            tlAreaList.DataSource = _foundationService.DoSelectByArea(e.Argument);
            tlAreaList.DataBind();
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="keyids">Keyid</param>
        /// <returns>是否删除成功</returns>
        [AjaxPro.AjaxMethod]
        public bool BulkDelete(string keyid)
        {

            return _foundationService.DeleteAreaAndParentkeyid(keyid);
        }
    }
}